package object;

import java.util.Random;

public class Food {
    private String name;
    private int count;

    public Food(String name) {
        this.name = name;
        Random r=new Random();
        count=r.nextInt(5);
    }
    public String sub(){
        if(count<1) return "不好意思，该食物没有了";
        count--;
        return "吃了一份"+name;
    }

    @Override
    public String toString() {//重写父类方法
        return "Food{" +
                "name='" + name + '\'' +
                ", count=" + count +
                '}';
    }
}
